package com.weishi.project.training.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.weishi.common.utils.StringUtils;
import com.weishi.common.utils.poi.ExcelUtil;
import com.weishi.framework.aspectj.lang.annotation.Log;
import com.weishi.framework.aspectj.lang.enums.BusinessType;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.framework.web.page.TableDataInfo;
import com.weishi.project.training.domain.*;
import com.weishi.project.training.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * 训练小组航道Controller
 */
@Api(value = "训练小组航道",description = "训练小组航道")
@RestController
@CrossOrigin("*")//解决移动端跨域
@RequestMapping("/trainingGroupChannel/trainingGroupChannel")
public class TrainingGroupChannelController extends BaseController {

    @Autowired
    private ITrainingGroupChannelService trainingGroupChannelService;

    /**
     * 运动员 接口
     */
    @Autowired
    private ISportsmanService sportsmanService;

    /**
     * 运动员成绩 接口
     */
    @Autowired
    private ITrainingAchievementService trainingAchievementService;

    /**
     * 分段成绩 接口
     */
    @Autowired
    private IDynamometerSubsectionService dynamometerSubsectionService;

    /**
     * 训练课 接口
     */
    @Autowired
    private ITrainingDayService trainingDayService;

    /**
     * 训练组 接口
     */
    @Autowired
    private ITrainingGroupService trainingGroupService;

    /**
     * 赛后数据表接口
     */
    @Autowired
    private IRaceDataService raceDataService;

    /**
     * 水上分段 接口
     */
    @Autowired
    private IHeartRateCountService heartRateCountService;



    /**
     * 根据艇只查询水上成绩
     */
    @PreAuthorize("@ss.hasPermi('trainingGroupChannel:trainingGroupChannel:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainingGroupChannel trainingGroupChannel) {
        if(trainingGroupChannel.getRowingKilometersTwo() == null){
            trainingGroupChannel.setRowingKilometers(0);
        }else{
            trainingGroupChannel.setRowingKilometers(trainingGroupChannel.getRowingKilometersTwo());
        }
        if("".equals(trainingGroupChannel.getBoatType())){
            trainingGroupChannel.setBoatType(null);
        }

        startPage();
        List<TrainingGroupChannel> list = trainingGroupChannelService.selectTrainingGroupChannelList(trainingGroupChannel);


        // 判断
        if(list.size() > 0){
            list.forEach( p-> {
                // 陆上成绩
                if(p.getFirstLevel().equals("land_specific_training_dynamometer")){
                    // 设置存储运动员 id 的容器
                    List<Integer> userId = new ArrayList<>();
                    List<TrainingAchievement> trainingAchievementList = trainingAchievementService
                            .list(Wrappers.<TrainingAchievement>lambdaQuery()
                                    .eq(TrainingAchievement::getChannelId , p.getId()));
                    if(trainingAchievementList.size() > 0){
                        trainingAchievementList.forEach( pp-> {
                            userId.add(pp.getSportsmanId());
                        });
                    }

                    // 设置存储运动员 名称 的容器
                    List<String> sportsmanName = new ArrayList<>();
                    // 根据 运动员的 id 查询运动员的名称 并且放到返回值中
                    if(userId.size() > 0){
                        userId.forEach( c-> {
                            List<Sportsman> sportsmanList = sportsmanService
                                    .list(Wrappers.<Sportsman>lambdaQuery()
                                            .eq(Sportsman::getId , c));

                            if(sportsmanList.size() > 0){
                                sportsmanList.forEach( pp-> {
                                    sportsmanName.add(pp.getName() + " ");
                                });
                            }
                        });
                    }

                    // 存入 运动员名称
                    p.setSportsmanName(sportsmanName);


                    // 水上成绩
                }else if(p.getFirstLevel().equals("special_training_water")){
                    // 设置存储运动员 id 的容器
                    List<Integer> userId = new ArrayList<>();
                    List<TrainingAchievement> trainingAchievementList = trainingAchievementService
                            .list(Wrappers.<TrainingAchievement>lambdaQuery()
                                    .eq(TrainingAchievement::getChannelId , p.getId()));
                    if(trainingAchievementList.size() > 0){
                        trainingAchievementList.forEach( pp-> {
                            userId.add(pp.getSportsmanId());
                        });
                    }

                    // 设置存储运动员 名称 的容器
                    List<String> sportsmanName = new ArrayList<>();
                    // 根据 运动员的 id 查询运动员的名称 并且放到返回值中
                    System.out.println();
                    if(userId.size() > 0){
                        userId.forEach( c-> {
                            List<Sportsman> sportsmanList = sportsmanService
                                    .list(Wrappers.<Sportsman>lambdaQuery()
                                            .eq(Sportsman::getId , c));
                            System.out.println();
                            if(sportsmanList.size() > 0){
                                sportsmanList.forEach( pp-> {
                                    sportsmanName.add(pp.getName() + " ");
                                });
                            }
                        });
                    }

                    // 存入 运动员名称
                    p.setSportsmanName(sportsmanName);

                    // 计算平均浆频
                    if(!"".equals(p.getSegmentPropellerFrequency()) && StringUtils.isNotNull(p.getSegmentPropellerFrequency())){
                        Double averageFrequency = 0.0;
                        List<String> averageFrequencyList = StringUtils.splitsSpace(p.getSegmentPropellerFrequency());
                        for (int a =0; a<averageFrequencyList.size(); a++){
                            averageFrequency += Double.parseDouble(averageFrequencyList.get(a));
                        }
                        p.setAveragePropellerFrequency(averageFrequency.intValue()/averageFrequencyList.size());
                    }

                    // 设置浆频
                    p.setPropellerFrequency(p.getSegmentPropellerFrequency());




















                }


            });


        }


        return getDataTable(list);
    }

    /**
     * 导出训练小组航道列表
     */
    @PreAuthorize("@ss.hasPermi('trainingGroupChannel:trainingGroupChannel:export')")
    @Log(title = "训练小组航道", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TrainingGroupChannel trainingGroupChannel) {
        List<TrainingGroupChannel> list = trainingGroupChannelService.selectTrainingGroupChannelList(trainingGroupChannel);

        // 判断
        if(list.size() > 0){
            list.forEach( p-> {
                // 陆上成绩
                if(p.getFirstLevel().equals("land_specific_training_dynamometer")){
                    // 水上成绩
                }else if(p.getFirstLevel().equals("special_training_water")){
                    // 设置存储运动员 id 的容器
                    List<Integer> userId = new ArrayList<>();
                    List<TrainingAchievement> trainingAchievementList = trainingAchievementService
                            .list(Wrappers.<TrainingAchievement>lambdaQuery()
                                    .eq(TrainingAchievement::getChannelId , p.getId()));
                    System.out.println();
                    if(trainingAchievementList.size() > 0){
                        trainingAchievementList.forEach( pp-> {
                            userId.add(pp.getSportsmanId());
                        });
                    }

                    // 设置存储运动员 名称 的容器
                    List<String> sportsmanName = new ArrayList<>();
                    // 根据 运动员的 id 查询运动员的名称 并且放到返回值中
                    System.out.println();
                    if(userId.size() > 0){
                        userId.forEach( c-> {
                            List<Sportsman> sportsmanList = sportsmanService
                                    .list(Wrappers.<Sportsman>lambdaQuery()
                                            .eq(Sportsman::getId , c));
                            System.out.println();
                            if(sportsmanList.size() > 0){
                                System.out.println();
                                sportsmanList.forEach( pp-> {
                                    sportsmanName.add(pp.getName() + " ");
                                });
                            }
                        });
                    }


                    // 存入 运动员名称
                    String sportsmanNames = "";
                    if(sportsmanName.size() > 0){
                        for (int s = 0; s<sportsmanName.size(); s++){
                            sportsmanNames += sportsmanName.get(s) + " ";
                        }
                    }
                    p.setSportsmanNames(sportsmanNames);

                    // 计算平均浆频
                    if(!"".equals(p.getSegmentPropellerFrequency()) && StringUtils.isNotNull(p.getSegmentPropellerFrequency())){
                        Double averageFrequency = 0.0;
                        System.out.println();
                        List<String> averageFrequencyList = StringUtils.splitsSpace(p.getSegmentPropellerFrequency());
                        for (int a =0; a<averageFrequencyList.size(); a++){
                            averageFrequency += Double.parseDouble(averageFrequencyList.get(a));
                        }
                        p.setAveragePropellerFrequency(averageFrequency.intValue()/averageFrequencyList.size());
                    }

                    // 设置浆频
                    p.setPropellerFrequency(p.getSegmentPropellerFrequency());

                    // 设置小组名称
                    Integer batch = p.getBatch()+1;
                    p.setBatchName("小组" + batch);

                    // 设置航道名称
                    Integer channelName = Integer.parseInt(p.getChannelName())+1;
                    p.setChannelName("第" + channelName + "航道");

                    // 设置分段成绩
                    if(!"".equals(p.getSegmentedTiming()) && StringUtils.isNotNull(p.getSegmentedTiming())){
                        String segmentedTiming = "";
                        Integer segmentedTimingIndex = 0;  // 分段成绩下标
                        List<String> segmentedTimingList = StringUtils.splitsSpace(p.getSegmentedTiming());
                        for (int s = 0; s<segmentedTimingList.size(); s++){
                            segmentedTimingIndex++;
                            segmentedTiming += "分段成绩" + segmentedTimingIndex + ": " + segmentedTimingList.get(s) + String.valueOf((char)10);
                        }
                        p.setSegmentedTiming(segmentedTiming);
                    }

                    // 设置平均浆频
                    if(!"".equals(p.getSegmentPropellerFrequency()) && StringUtils.isNotNull(p.getSegmentPropellerFrequency())){
                        Double averageFrequency = 0.0;
                        List<String> averageFrequencyList = StringUtils.splitsSpace(p.getSegmentPropellerFrequency());
                        for (int a =0; a<averageFrequencyList.size(); a++){
                            System.out.println();
                            averageFrequency += Double.parseDouble(averageFrequencyList.get(a));
                        }
                        p.setAveragePropellerFrequency(averageFrequency.intValue()/averageFrequencyList.size());
                    }


                    // 设置分段船速
                    if(!"".equals(p.getSectionalSpeed()) && StringUtils.isNotNull(p.getSectionalSpeed())){
                        String sectionalSpeed = "";
                        Integer sectionalSpeedIndex = 0;  // 分段船速下标
                        List<String> segmentedTimingList = StringUtils.splitsSpace(p.getSectionalSpeed());
                        for (int s = 0; s<segmentedTimingList.size(); s++){
                            sectionalSpeedIndex++;
                            sectionalSpeed += "分段船速" + sectionalSpeedIndex + ": " + segmentedTimingList.get(s) + String.valueOf((char)10);
                        }
                        p.setSectionalSpeed(sectionalSpeed);
                    }

                    // 设置分段浆频
                    if(!"".equals(p.getPropellerFrequency()) && StringUtils.isNotNull(p.getPropellerFrequency())){
                        String segmentPropellerFrequency = "";
                        Integer segmentPropellerFrequencyIndex = 0;  // 分段浆频下标
                        List<String> segmentedTimingList = StringUtils.splitsSpace(p.getPropellerFrequency());
                        for (int s = 0; s<segmentedTimingList.size(); s++){
                            segmentPropellerFrequencyIndex++;
                            segmentPropellerFrequency += "分段浆频" + segmentPropellerFrequencyIndex + ": " + segmentedTimingList.get(s) + String.valueOf((char)10);
                        }
                        p.setSegmentPropellerFrequency(segmentPropellerFrequency);
                    }







                }
            });
        }

        ExcelUtil<TrainingGroupChannel> util = new ExcelUtil<>(TrainingGroupChannel.class);
        return util.exportExcel(list, "皮划艇训练成绩");
    }

    /**
     * 获取训练小组航道基本信息
     */
    @PreAuthorize("@ss.hasPermi('trainingGroupChannel:trainingGroupChannel:query')")
    @GetMapping("/{id}")
    public AjaxResult getBaseInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(trainingGroupChannelService.getTrainingGroupChannelDetails(id));
    }

    /**
     * 获取训练小组航道+运动员成绩详细信息
     */
    @GetMapping("/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(trainingGroupChannelService.getTrainingGroupChannelAndAchievement(id));
    }

    /**
     * 新增训练小组航道
     */
    @PreAuthorize("@ss.hasPermi('trainingGroupChannel:trainingGroupChannel:add')")
    @Log(title = "训练小组航道", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainingGroupChannel trainingGroupChannel) {
        trainingGroupChannel.setCtime(new Date());
        trainingGroupChannel.setPropellerFrequency(trainingGroupChannel.getSegmentPropellerFrequency());
        trainingGroupChannelService.add(trainingGroupChannel);
        // 水上
        if(trainingGroupChannel.getFirstLevel().equals("special_training_water")){

        }else{

                // 新增
                //接收 分段浆频
                List<String> segmentPropellerFrequency = StringUtils.splitsSpace(trainingGroupChannel.getSegmentPropellerFrequency());
                // 接收 分段心率
                List<TrainingAchievement> segmentHeartRate = trainingGroupChannel.getPerson();
                String segmentHeartRate2 = "";
                for (int i = 0; i<segmentHeartRate.size(); i++){
                    segmentHeartRate2 += segmentHeartRate.get(i).getSegmentHeartRate() + " ";
                }
                List<String> segmentHeartRate3 = StringUtils.splitsSpace(segmentHeartRate2);
                // 接收 分段功率
                List<String> segmentPower = StringUtils.splitsSpace(trainingGroupChannel.getSegmentPower());
                // 接收 分段瓦特
                List<String> segmentWatt = StringUtils.splitsSpace(trainingGroupChannel.getSegmentWatt());
                // 接收 分段成绩
                List<String> segmentedTiming = StringUtils.splitsSpace(trainingGroupChannel.getSegmentedTiming());

                if(segmentPropellerFrequency.size() > 0 && segmentPropellerFrequency.size() == segmentPropellerFrequency.size()){
                    for (int i = 0; i<segmentPropellerFrequency.size(); i++){
                        DynamometerSubsection dynamometerSubsections = new DynamometerSubsection();
                        StringUtils.copyProperties(trainingGroupChannel , dynamometerSubsections);
                        dynamometerSubsections.setPropellerFrequency(segmentPropellerFrequency.get(i));
                        dynamometerSubsections.setChannelId(trainingGroupChannel.getId());
                        dynamometerSubsections.setSportsmanId(segmentHeartRate.get(0).getSportsmanId());
                        dynamometerSubsections.setTrainingDayId(trainingGroupChannel.getTrainingDayId());
                        dynamometerSubsectionService.save(dynamometerSubsections);

                        // 更新分段成绩
                        DynamometerSubsection dynamometerSubsections1 = new DynamometerSubsection();
                        dynamometerSubsections1.setHeartRate(Integer.parseInt(segmentHeartRate3.get(i)));
                        dynamometerSubsections1.setPower(segmentPower.get(i));
                        dynamometerSubsections1.setWatt(segmentWatt.get(i));
                        dynamometerSubsections1.setPulpNumber(trainingGroupChannel.getPulpNumber());
                        dynamometerSubsections1.setSpeed(trainingGroupChannel.getSpeed());
                        dynamometerSubsections1.setPeakForce(Double.valueOf(trainingGroupChannel.getPeakForce()));
                        dynamometerSubsections1.setAverageForce(Double.valueOf(trainingGroupChannel.getAverageForce()));
                        dynamometerSubsections1.setPulpNumber(trainingGroupChannel.getPulpNumber());
                        dynamometerSubsections1.setSegmentNumber(i);
                        dynamometerSubsections1.setTrainingMode(trainingDayService.getById(trainingGroupChannel.getTrainingDayId()).getTrainingMode());
                        if(trainingDayService.getById(trainingGroupChannel.getTrainingDayId()).getTrainingMode() == 0){
                            dynamometerSubsections1.setLengthTime(segmentedTiming.get(i));
                        }else{
                            dynamometerSubsections1.setMileage(Double.valueOf(segmentedTiming.get(i)));
                        }
                        dynamometerSubsections1.setGroupName(trainingGroupService.getById(trainingGroupChannel.getGroupId()).getGroupName());
                        dynamometerSubsections1.setSportsmanName(sportsmanService.getById(segmentHeartRate.get(0).getSportsmanId()).getName());
                        dynamometerSubsections1.setSex(sportsmanService.getById(segmentHeartRate.get(0).getSportsmanId()).getSex());
                        dynamometerSubsections1.setCtime(new Date());
                        dynamometerSubsections1.setId(dynamometerSubsections.getId());
                        dynamometerSubsectionService.updateById(dynamometerSubsections1);
                    }
                }

        }
        return AjaxResult.success();
    }

    /**
     * 修改训练小组航道
     */
    @PreAuthorize("@ss.hasPermi('trainingGroupChannel:trainingGroupChannel:edit')")
    @Log(title = "训练小组航道", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainingGroupChannel trainingGroupChannel) {
        trainingGroupChannel.setCtime(new Date());
        trainingGroupChannel.setPropellerFrequency(trainingGroupChannel.getSegmentPropellerFrequency());
        trainingGroupChannelService.updateById(trainingGroupChannel);
        // 水上
        if(trainingGroupChannel.getFirstLevel().equals("special_training_water")){
            if(trainingGroupChannel.getPerson()!=null && trainingGroupChannel.getPerson().size()>0){
                for(TrainingAchievement trainingAchievement : trainingGroupChannel.getPerson()){
                    System.out.println();
                    trainingAchievement.setChannelId(trainingGroupChannel.getId());
                    trainingAchievement.setCtime(new Date());
                    // 接收 分段心率
                    List<TrainingAchievement> segmentHeartRate = trainingGroupChannel.getPerson();
                    String segmentHeartRate2 = "";
                    for (int i = 0; i<segmentHeartRate.size(); i++){
                        segmentHeartRate2 += segmentHeartRate.get(i).getSegmentHeartRate() + " ";
                    }
                    trainingAchievement.setHeartRate(segmentHeartRate2); // 存储分段心率

                    trainingAchievementService.saveOrUpdate(trainingAchievement);
                }
            }
        }else{


            /**
             * 修改分段成绩数据
             */
            List<DynamometerSubsection> dynamometerSubsection = dynamometerSubsectionService
                    .list(Wrappers.<DynamometerSubsection>lambdaQuery()
                            .eq(DynamometerSubsection::getChannelId, trainingGroupChannel.getId())
                            .eq(DynamometerSubsection::getGroupId , trainingGroupChannel.getGroupId())
                            .eq(DynamometerSubsection::getTrainingDayId , trainingGroupChannel.getTrainingDayId()));

            // 修改
            if(dynamometerSubsection.size() > 0){
                System.out.println();
                dynamometerSubsection.forEach( p->{
                    // 先把之前的数据删掉，然后新增
                    dynamometerSubsectionService.removeById(p.getId());
                });

                //接收 分段浆频
                List<String> segmentPropellerFrequency = StringUtils.splitsSpace(trainingGroupChannel.getSegmentPropellerFrequency());
                // 接收 分段心率
                List<TrainingAchievement> segmentHeartRate = trainingGroupChannel.getPerson();
                String segmentHeartRate2 = "";
                for (int i = 0; i<segmentHeartRate.size(); i++){
                    segmentHeartRate2 += segmentHeartRate.get(i).getSegmentHeartRate() + " ";
                }
                List<String> segmentHeartRate3 = StringUtils.splitsSpace(segmentHeartRate2);
                // 接收 分段功率
                List<String> segmentPower = StringUtils.splitsSpace(trainingGroupChannel.getSegmentPower());
                // 接收 分段瓦特
                List<String> segmentWatt = StringUtils.splitsSpace(trainingGroupChannel.getSegmentWatt());
                // 接收 分段成绩
                List<String> segmentedTiming = StringUtils.splitsSpace(trainingGroupChannel.getSegmentedTiming());

                if(segmentPropellerFrequency.size() > 0 && segmentPropellerFrequency.size() == segmentPropellerFrequency.size()){
                    for (int i = 0; i<segmentPropellerFrequency.size(); i++){
                        System.out.println();
                        DynamometerSubsection dynamometerSubsections = new DynamometerSubsection();
                        StringUtils.copyProperties(trainingGroupChannel , dynamometerSubsections);
                        dynamometerSubsections.setPropellerFrequency(segmentPropellerFrequency.get(i));
                        dynamometerSubsections.setChannelId(trainingGroupChannel.getId());
                        dynamometerSubsections.setSportsmanId(segmentHeartRate.get(0).getSportsmanId());
                        dynamometerSubsections.setTrainingDayId(trainingGroupChannel.getTrainingDayId());
                        dynamometerSubsectionService.save(dynamometerSubsections);

                        // 更新分段成绩
                        DynamometerSubsection dynamometerSubsections1 = new DynamometerSubsection();
                        dynamometerSubsections1.setHeartRate(Integer.parseInt(segmentHeartRate3.get(i)));
                        dynamometerSubsections1.setPower(segmentPower.get(i));
                        dynamometerSubsections1.setWatt(segmentWatt.get(i));
                        dynamometerSubsections1.setPulpNumber(trainingGroupChannel.getPulpNumber());
                        dynamometerSubsections1.setSpeed(trainingGroupChannel.getSpeed());
                        dynamometerSubsections1.setPeakForce(Double.valueOf(trainingGroupChannel.getPeakForce()));
                        dynamometerSubsections1.setAverageForce(Double.valueOf(trainingGroupChannel.getAverageForce()));
                        dynamometerSubsections1.setPulpNumber(trainingGroupChannel.getPulpNumber());
                        dynamometerSubsections1.setSegmentNumber(i);
                        dynamometerSubsections1.setTrainingMode(trainingDayService.getById(trainingGroupChannel.getTrainingDayId()).getTrainingMode());
                        if(trainingDayService.getById(trainingGroupChannel.getTrainingDayId()).getTrainingMode() == 0){
                            dynamometerSubsections1.setLengthTime(segmentedTiming.get(i));
                        }else{
                            dynamometerSubsections1.setMileage(Double.valueOf(segmentedTiming.get(i)));
                        }
                        dynamometerSubsections1.setGroupName(trainingGroupService.getById(trainingGroupChannel.getGroupId()).getGroupName());
                        dynamometerSubsections1.setSportsmanName(sportsmanService.getById(segmentHeartRate.get(0).getSportsmanId()).getName());
                        dynamometerSubsections1.setSex(sportsmanService.getById(segmentHeartRate.get(0).getSportsmanId()).getSex());
                        dynamometerSubsections1.setCtime(new Date());
                        dynamometerSubsections1.setId(dynamometerSubsections.getId());
                        dynamometerSubsectionService.updateById(dynamometerSubsections1);
                    }
                }
            }
        }
        return AjaxResult.success();
    }

    /**
     * 删除训练小组航道
     */
    @PreAuthorize("@ss.hasPermi('trainingGroupChannel:trainingGroupChannel:remove')")
    @Log(title = "训练小组航道", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        trainingGroupChannelService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }

    @PreAuthorize("@ss.hasPermi('trainingGroupChannel:trainingGroupChannel:list')")
    @GetMapping("/getChannelNameList")
    public TableDataInfo getChannelNameList(TrainingGroupChannel trainingGroupChannel) {
        startPage();
        List<TrainingGroupChannel> list = trainingGroupChannelService.getChannelNameList();
        return getDataTable(list);
    }


    @ApiOperation("PC 端 -- 新增赛后数据")
    @RequestMapping(value = "/addRaceData", method = RequestMethod.POST)
    public AjaxResult addRaceData(@RequestBody JSONObject jsonObject) {
        // 查询运动员详情
        Sportsman sportsman = sportsmanService.getById(Integer.parseInt(jsonObject.get("sportsmanId").toString()));

        // 查询前端发送的 list 数据
        com.alibaba.fastjson.JSONArray jsonArray = jsonObject.getJSONArray("list");
        List<RaceData> raceDataList = JSON.parseArray(jsonArray.toString(), RaceData.class);
        if(raceDataList.size() > 0){
            System.out.println();
            raceDataList.forEach( p-> {
                RaceData raceData = new RaceData();
                System.out.println();
                StringUtils.copyProperties(p , raceData);
                raceData.setSportsmanId(sportsman.getId());
                raceData.setSportsmanName(sportsman.getName());
                raceData.setSportsmanSex(sportsman.getSex());
                System.out.println();
                raceData.setCtime(new Date());
                raceData.setTrainingDayId(Integer.parseInt(jsonObject.get("trainingDayId").toString()));
                raceData.setGroupId(Integer.parseInt(jsonObject.get("trainingDayId").toString()));
                raceDataService.save(raceData);
            });
        }
        return AjaxResult.success();
    }


    @ApiOperation("PC 端 -- 查询赛后数据")
    @RequestMapping(value = "/getRaceDataList", method = RequestMethod.GET)
    public AjaxResult getRaceDataList(HttpServletRequest request) {
        String sportsmanId = request.getParameter("sportsmanId");
        String trainingDayId = request.getParameter("trainingDayId");
        return AjaxResult.success(Optional.ofNullable(raceDataService
                .list(Wrappers.<RaceData>lambdaQuery()
                        .eq(RaceData::getSportsmanId , Integer.parseInt(sportsmanId))
                        .eq(RaceData::getTrainingDayId , Integer.parseInt(trainingDayId)))));
    }


    @ApiOperation("PC 端 -- 修改赛后数据")
    @RequestMapping(value = "/updateRaceData", method = RequestMethod.POST)
    public AjaxResult updateRaceData(@RequestBody JSONObject jsonObject) {

        /**
         * 修改就是将之前的数据删掉，然后重新新增
         */
        List<RaceData> raceDataList2 = raceDataService
                .list(Wrappers.<RaceData>lambdaQuery()
                        .eq(RaceData::getSportsmanId , Integer.parseInt(jsonObject.get("sportsmanId").toString()))
                        .eq(RaceData::getTrainingDayId , Integer.parseInt(jsonObject.get("trainingDayId").toString())));

        // 删除数据
        if(raceDataList2.size() > 0){
            raceDataList2.forEach( p-> {
                raceDataService.removeById(p.getId());
            });
        }

        // 查询运动员详情
        Sportsman sportsman = sportsmanService.getById(Integer.parseInt(jsonObject.get("sportsmanId").toString()));

        // 查询前端发送的 list 数据
        com.alibaba.fastjson.JSONArray jsonArray = jsonObject.getJSONArray("list");
        List<RaceData> raceDataList = JSON.parseArray(jsonArray.toString(), RaceData.class);
        if(raceDataList.size() > 0){
            System.out.println();
            raceDataList.forEach( p-> {
                System.out.println();
                RaceData raceData = new RaceData();
                System.out.println();
                StringUtils.copyProperties(p , raceData);
                raceData.setSportsmanId(sportsman.getId());
                raceData.setSportsmanName(sportsman.getName());
                raceData.setSportsmanSex(sportsman.getSex());
                raceData.setCtime(new Date());
                raceData.setTrainingDayId(Integer.parseInt(jsonObject.get("trainingDayId").toString()));
                raceData.setGroupId(Integer.parseInt(jsonObject.get("trainingDayId").toString()));
                raceDataService.save(raceData);
            });
        }
        return AjaxResult.success();
    }












}